import type { AddAddressItem, AddressListType } from "@/types/address";
import { http } from "@/untils/request";

/**
 * 添加收货地址
 * @returns 
 */
export const addAddressAPI = (data: AddAddressItem) => {
    return http({
        url: '/member/address',
        method: 'POST',
        data
    })
}

/**
 * 获取收货地址列表
 * @returns 
 */
export const getAddressListAPI = () => {
    return http<AddressListType[]>({
        url: '/member/address',
        method: 'GET'
    })
}

/**
 * 获取收货地址详情
 * @param id 
 * @returns 
 */
export const getAddressDetailAPI = (id: string) => {
    return http<AddressListType>({
        url: `/member/address/${id}`,
        method: 'GET'
    })
}

/**
 * 修改收货地址
 * @param id 
 * @param data 
 * @returns 
 */
export const updateAddressAPI = (id: string, data: AddAddressItem) => {
    return http({
        url: `/member/address/${id}`,
        method: 'PUT',
        data
    })
}

/**
 * 删除收货地址
 * @param id 
 * @returns 
 */
export const deleteAddressAPI = (id: string) => {
    return http({
        url: `/member/address/${id}`,
        method: 'DELETE'
    })
}